package com.tomecode.ora.jdev.ext.showmepassword;

import com.tomecode.ora.jdev.ext.showmepassword.utils.JDeveloperConnectionsParser;
import com.tomecode.ora.jdev.ext.showmepassword.utils.Login;

import java.io.File;

import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

import java.net.URL;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;

import java.util.Map;

import java.util.Set;

import oracle.ide.Context;
import oracle.ide.ExtensionRegistry;
import oracle.ide.controller.Controller;
import oracle.ide.controller.IdeAction;
import oracle.ide.extension.RegisteredByExtension;
import oracle.ide.log.LogManager;

/**
 * 
 * @author Tomas (Tome) Frastia
 * @see http://www.tomecode.com
 * 
 *      Controller for action
 *      com.tomecode.ora.jdev.ext.showmepasswordjdev.
 */
@RegisteredByExtension("com.tomecode.ora.jdev.ext.showmepasswordjdev")
public final class ShowMePasswordJdevController implements Controller {

	public boolean update(IdeAction action, Context context) {
		action.setEnabled(true);
		return true;
	}

	public boolean handleEvent(IdeAction action, Context context) {
		try {
			LogManager.getLogManager().showLog();
			LogManager.getLogManager().getIdeLogWindow().log("\nStarting parse connections...");
			List<Login> logins = JDeveloperConnectionsParser.parseConnection();
			LogManager.getLogManager().getIdeLogWindow().log("\nFinish parse connections...");
			PasswordWindow.showMe(logins);
		} catch (Exception e) {
			LogManager.getLogManager().getIdeLogWindow().log("\nError" + e.getMessage());
		}
		return false;
	}
}
